Skip to main content

Adding filter conditions to Event Strategies

4 Tasks

15 mins

Pega Platform
Visible to: All users
Beginner Pega Platform English

Scenario

In the Sample application, the Sample-Data-Filter Class is created for the exercise. The Class uses the following data structure:

Field Type Description

EventID

Identifier

A unique identifier for every incoming record.

EventKey

Text

A key field that is used to group the incoming events.

EventText

Text

A field that can hold text values.

ValueA

Integer

A field that can hold integer values.

ValueB

Integer

A field that can hold integer values.

Create an Event Strategy in the Sample-Data-Filter Class to experiment with different filter options.

Use the following credentials to log in to the exercise system:

Role User name Password
System architect SystemArchitect rules

Your Assignment consists of the following tasks:

Task 1: Filtering events using local variables

Create a new Event Strategy in the Sample-Data-Window Class and name it Filter Events.

Configure the Event Strategy:

  1. Use the EventKey field as the Event key and System time as the Event timestamp.
  2. Add a Filter component.
  3. In the Filter component, define a new Local variable; ValueC. ValueC is the sum of ValueA plus ValueB.
  4. Filter Events with ValueC greater than or equal to 50.

Task 2: Test the Filter Events Event Strategy

Test the behavior of the Event Strategy with a Filter component by using a local variable.

Scenario 1: Send five events for any Event Key using the values 10 and 30.

Scenario 2: Send a single event for any Event Key using the values 20 and 30.

Confirm that the events are filtered in the first scenario, and that the event passes the filter in the second scenario.

Task 3: Applying multiple filters

Add a second Filter condition to satisfy the following requirement.

The Events can be emitted when the EventText contains the word "Pass" (including the quotation marks).

Task 4: Test the Filter Events Event Strategy with multiple filters

Test the behavior of the Event Strategy with the second Filter component using the new Filter component.

Test Scenario 1: Send a single event for any Event Key using the following values:

  • ValueA = 20
  • ValueB =30
  • EventText = "Fail"

Test Scenario 2: Send a single event for any Event Key using the following values:

  • ValueA = 10
  • ValueB =5
  • EventText = "Pass"

Confirm that for both scenarios, the events are emitted.

You must initiate your own Pega instance to complete this Challenge.

Initialization may take up to 5 minutes so please be patient.

Challenge Walkthrough

Detailed Tasks

1 Filtering events using local variables

  1. Log in as the system architect:
    1. In the User name field, enter SystemArchitect.
    2. In the Password field, enter rules.
  2. In the navigation pane of Dev Studio, click App to open the Application Explorer.
  3. In the Application Explorer, search for the Sample-Data-Filter Class.
  4. In the Application Explorer, right-click on the Sample-Data-Filter Class, then select Create > Decision> Event Strategy.
  5. On the Create Event Strategy tab, create a new Event Strategy:
    1. In the Label field, enter Filter Events.
    2. In the upper-right corner, click Create and open.
      Create and open
  6. On the Edit Event Strategy: Filter Events rule form, double-click on the Real-time data component to set up the Real-time data properties.
    1. In the Event key list, select EventKey.
    2. In the Event timestamp, confirm that System time is selected.
    3. Notice the available fields: ValueA, ValueB, and EventText.
    4. Click Submit.
      submit
  7. On the canvas, on the first shape, click Add > Filter to add a new Filter component.
  8. On the canvas, double-click on the Filter component to set up the Filter properties.
    1. In the Name field, enter First filter.
    2. In the Local variables section, click Add variable to define a new variable.
      Tip: The local variables that are added in a Filter component are only available in the same component. They cannot be used in other components.
    3. In the first field, enter ValueC.
      Tip: ValueC is a variable that you set in the runtime. This field is not part of the Data Model. You can create multiple variables and use them in the Filter Component.
    4. In the second field, enter or select ValueA.
    5. In the third field, select +.
    6. In the last field, enter or select ValueB.
      valueB
  1. In the Filter conditions section, click Add condition to define a new Condition.
    1. In the Field column, enter or select ValueC.
      Tip: Note that the newly defined variable is automatically added to the list of available fields you can select in the [VARIABLES] list.
    2. In the Operator list, select >=.
    3. In the Expression column, enter 50.
      Expression
    4. Click Submit.
  1. In the upper-right corner, click Save.

2 Test the Filter Events Event Strategy

  1. On the Event Strategy: Filter Events rule form, in the upper-right corner, click Actions > Run to open the Run window.
  2. In the Run window, complete the following settings:
    1. In the Number of events to send field enter 5, to send five events.
    2. In the EventKey field, enter any value, for example, Key-1.
      Note: The Event Key field is used for grouping the incoming events. You can add additional keys in the Window component.
    3. In the ValueA field, enter 10.
    4. In the ValueB field, enter 30.
      Note: The sum of ValueA and ValueB is set to the local variable ValueC. In this case, the sum equals forty, which does not satisfy the "ValueC greater than or equal to fifty" condition.
    5. In the upper-right corner, click Run to send five events to the Event Strategy.
      Run
  1. Analyze the results:
    1. The Sent events (5) section now has five pages.
    2. The Emitted events (0) section currently has no events emitted. This is because none of the events fulfilled the Filter condition.
      Emitted events
  2. In the Run window, click Clear events to start a new test case, then complete the following settings:
    1. In the Number of events to send field enter 1, to send a single event.
    2. In the EventKey field, enter any value, for example, Key-2.
    3. In the ValueA field, enter 20.
    4. In the ValueB field, enter 30.
      ValueB 2
  3. In the upper-right corner, click Run to send a single event to the Event Strategy.
    1. The Sent events (1) section now has now one page.
    2. The Emitted events (1) section has one event emitted. This is because the event fulfilled the Filter condition where the sum of two fields is fifty.

3 Applying multiple filters

  1. On the Event Strategy: Filter Events rule form, in the upper-right corner, click Check out to update the Event Strategy.
  2. On the canvas, on the First filter shape, click Add filter to add a new Filter component.
    Tip: This Filter condition uses the "Or" operand. Events that fulfill at least one of the Filter Components continue along the Event Strategy. To create conditions with the "And" operand, you can add a criterion within the same Filter component or add a second Filter component after the first Filter component.
  1. On the canvas, double-click the Filter component to set up the Filter properties.
    Filter properties
  2. In the Name field, enter Second filter.
  3. In the Filter conditions section, click Add condition to define a new condition:
    1. In the Field column, enter or select EventText.
    2. In the Operator list, select Contains.
      Tip: In the list of available operators, the Matches operator allows you to look for matching patterns in a text field.
      Use a regular expression to specify the pattern that you want to match. See the followingexamples of operators and syntax:
      [a-z] - any character from 'a' to 'z'
      [2-8] - any number from 2 to 8
      \d – digit
      \w – word
      a* - zero or more 'a' characters
      a? - zero or one 'a' character
      a+ - one or more 'a' characters
      Here are two common usage examples:
      Social Security number: \d{3}-\d{2}-\d{4}
      Email address: [\w-]+@([\w-]+\.)+[\w-]+
    3. In the Expression column, enter "Pass".
    4. Click Submit.
      Submit 5
  1. In the upper-right corner, click Save.

4 Test the Filter Events Event Strategy with multiple filters

  1. On the Edit Event Strategy: Filter Events rule form, in the upper-right corner, click Actions > Run to open the run window.
  2. On the Run window, complete the following settings:
    1. In the EventKey field, enter any value, for example, Key-3.
    2. In the ValueA field, enter 20.
    3. In the ValueB field, enter 30.
    4. In the EventText field, enter Fail.
    5. In the upper-right corner, click Run to send a single event to the Event Strategy.
      Run 2
  3. Analyze the results:
    1. The Sent events (1) section now has a single page.
    2. The Emitted events (1) section has one event emitted. This is because the event fulfilled the first filter condition where the sum of two fields is fifty. The second condition EventText contains "Pass" and is not fulfilled. The filters use the "Or" operand, so the event is emitted.
      emitted events 3
  4. In the Run window, click Clear events to start a new test case.
  5. In the Run window, configure the following settings:
    1. In the EventKey field, enter any value, for example, Key-4.
    2. In the ValueA field, enter 0.
    3. In the ValueB field, enter 5.
    4. In the EventText field, enter Pass.
    5. In the upper-right corner, click Run only once to send a single event to the Event Strategy.
      Run 6
  6. Analyze the results:
    1. The Sent events (1) section now has a single page.
    2. The Emitted events (1) section has one event emitted. This is because the event did not fulfill the first filter condition where the sum of two fields is fifty but the second condition EventText contains "Pass" is fulfilled. The filters use the "Or" operand, so the event is emitted.
      emitted events 5


Available in the following mission:

If you are having problems with your training, please review the Pega Academy Support FAQs.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Academy has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice